package com.busionline.wotu.baselibrary.base;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;
import butterknife.Unbinder;


/**
 * fragment基类
 * Created by chenwuchao on 2017/7/26.
 * 子类在lazyLoad()方法中进行相应处理就可以实现懒加载(仅在pageAdapter中有效果)
 */

public abstract class BaseFragment extends Fragment {
    protected static String TAG = "BaseFragment";
    protected View contentView;
    protected Context mContext;
    private Unbinder unbinder;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        TAG = this.getClass().getSimpleName();
        mContext = getActivity();
        contentView = inflater.inflate(setContentView(), container, false);
        unbinder = ButterKnife.bind(this, contentView);
        initView();
        initData();
        return contentView;
    }

    /**
     * 启动Activity
     *
     * @param clazz
     */
    public void startActivity(Class<? extends Activity> clazz) {
        Intent intent = new Intent(mContext, clazz);
        startActivity(intent);
    }

    /**
     * 加载布局
     *
     * @return
     */
    protected abstract int setContentView();

    /**
     * 初始化布局
     */
    protected abstract void initView();

    /**
     * 初始化数据
     */
    protected abstract void initData();

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (unbinder != null) {
            unbinder.unbind();
        }
    }
}
